//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class PatternFillProperties : LineFillProperties
    {
        private ColorBase bgClr;
        private ColorBase fgClr;
        private PresetPatternValue? prst;

        public ColorBase ForegroundColor
        {
            get { return fgClr; }
            set { fgClr = value; }
        }

        public ColorBase BackgroundColor
        {
            get { return bgClr; }
            set { bgClr = value; }
        }

        public PresetPatternValue? Preset
        {
            get { return prst; }
            set { prst = value; }
        }

        internal override Brush ToBrush(ColorScheme colorScheme)
        {
            throw new NotImplementedException();
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("pattFill"))
            {
                Preset = c.GetOptionalEnum<PresetPatternValue>("prst");
                ForegroundColor = ColorBase.ReadOptionalColorAs("fgClr", c);
                BackgroundColor = ColorBase.ReadOptionalColorAs("bgClr", c);
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("pattFill"))
            {
                c.SetOptionalEnum("prst", Preset);
                if (ForegroundColor != null)
                {
                    using (WriteContext c2 = c.Write("fgClr"))
                    {
                        c2.WriteElement(ForegroundColor);
                    }
                }
                if (BackgroundColor != null)
                {
                    using (WriteContext c2 = c.Write("bgClr"))
                    {
                        c2.WriteElement(BackgroundColor);
                    }
                }
            }
        }
    }
}